<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>sku列表</title>
</head>
<body>
	<form id="searchForm">
		<div class="form-group row">
			<label for="nameid">关&nbsp;&nbsp;&nbsp;&nbsp;键&nbsp;&nbsp;&nbsp;&nbsp;字</label>
			<div class="col-sm-3">
				<input type="text" name="keyWord" id="nameid"
					value="${skuVo.keyWord}">
			</div>

			<label for="captionid">价&nbsp;&nbsp;格&nbsp;&nbsp;范&nbsp;&nbsp;围</label>
			<div class="col-sm-6">
				从<input type="text" name="minPrice" value="${skuVo.minPrice}">
				到<input type="text" name="maxPrice" value="${skuVo.maxPrice}">
			</div>

		</div>
		<div class="form-group row">
			<label for="brandDomid">更&nbsp;&nbsp;新&nbsp;时&nbsp;间</label>
			<div class="col-sm-4">
				从<input type="date" name="minTime"
					value="<fmt:formatDate value="${skuVo.minTime}" pattern="yyyy-MM-dd"/>">
				到<input type="date" name="maxTime"
					value="<fmt:formatDate value="${skuVo.maxTime}" pattern="yyyy-MM-dd"/>">
			</div>
		</div>

		<div class="form-group row">
			<label for="nameid">排序数据项：</label>
			<div class="col-sm-4">

				&nbsp;&nbsp;<input type="checkbox" value="id" name="sortColumn" <c:forEach items="${skuVo.sortColumn}" var="col"> <c:if test="${col=='id'}">checked="checked" </c:if> </c:forEach>>id
				&nbsp;&nbsp;<input type="checkbox" name="sortColumn" <c:forEach items="${skuVo.sortColumn}" var="col"> <c:if test="${col=='price'}">checked="checked" </c:if> </c:forEach> value="price">价格 &nbsp;&nbsp;
					
					<input type="checkbox" name="sortColumn" <c:forEach items="${skuVo.sortColumn}" var="col"> <c:if test="${col=='stock_count'}">checked="checked" </c:if> </c:forEach> value="stock_count"> 库存 &nbsp;&nbsp;
					<input type="checkbox" name="sortColumn" <c:forEach items="${skuVo.sortColumn}" var="col"> <c:if test="${col=='update_time'}">checked="checked" </c:if> </c:forEach> value="update_time"> 更新时间
			</div>

			<label for="nameid">排序方式：</label>
			<div class="col-sm-4">
				<!-- 此处sortType和vo里一致才行 -->
				<select name="sortType" id="orderTypeId">
					<option value="ASC">请选择</option>
					<option value="ASC" ${skuVo.sortType=='ASC'? 'selected':'' }>升序</option>
					<option value="DESC" ${skuVo.sortType=='DESC'? 'selected':'' }>降序</option>
				</select>
			</div>
		</div>

		<button type="button" class="btn btn-danger" onclick="goPage(1)">查询</button>

		<button type="button" class="btn btn-danger" onclick="delBatch()">批量删除</button>

	</form>

	<table class="table">
		<tr>
			<th>id</th>
			<th>商品名称</th>
			<th>品牌</th>
			<th>分类</th>
			<th>标题</th>
			<th>卖点</th>
			<th>价格</th>
			<th>库存</th>
			<th>更新时间</th>
			<th>图片</th>
			<th>操作</th>
		</tr>
		<c:forEach items="${info.list }" var="sku">
			<tr>
				<td>${sku.id}<input type="checkbox" class="chkb"
					value="${sku.id }">
				</td>
				<td>${sku.spu.goodsName}</td>
				<td>${sku.spu.brand.name}</td>
				<td>${sku.spu.category.name}</td>
				<td>${sku.title}</td>
				<td width="200px">${sku.sellPoint}</td>
				<td>${sku.price}</td>
				<td>${sku.stockCount}</td>
				<td><fmt:formatDate value="${sku.updateTime}"
						pattern="yyyy-MM-dd" /></td>
				<td><img src="/pic/${sku.image}" width="50px" height="50px"></img></td>
				<td>
					<div class="btn-group" role="group" aria-label="Basic example">
						<button type="button" class="btn btn-secondary"
							onclick="toUpdate(${sku.id})">修改</button>
						<button type="button" class="btn btn-secondary"
							onclick="del(${sku.id})">删除</button>
					</div>
				</td>
			</tr>
		</c:forEach>
	</table>
	<jsp:include page="/WEB-INF/view/common/pages.jsp"></jsp:include>
</body>
<script type="text/javascript">

	//跳转到修改页面
	function toUpdate(skuId){
		$("#workArea").load("sku/toUpdate?skuId="+skuId);
	}
	function del(id){
		var ids = new Array();
		ids.push(id);
		if(ids.length!=0){
			$.post("./sku/delBatch",{'ids':ids.join(",")},function(data){
				if(data){
					alert("success!!")
					goPage(1);
				}else{
					alert("fail!!!!!")
				}
			})
		}else{
			alert("请选择")
		}
	}

	function delBatch(){
		var ids = new Array();
		$(".chkb:checked").each(function(){
			var id = $(this).val();
			//alert(id)
			ids.push(id);
		})
		
		if(ids.length!=0){
			$.post("./sku/delBatch",{'ids':ids.join(",")},function(data){
				if(data){
					alert("success!!")
					goPage(1);
				}else{
					alert("fail!!!!!")
				}
			})
		}else{
			alert("请选择")
		}
	}
	
	function goPage(pageNum) {
		$("#workArea").load("./sku/list?pageNum=" + pageNum,$("#searchForm").serialize());
	}
</script>
</html>